package org.yoyo.classroom.service.impl;

import com.baomidou.mybatisplus.plugins.Page;

import org.yoyo.classroom.domain.po.BookingRule;
import org.yoyo.classroom.domain.po.StudyRoomCategory;
import org.yoyo.classroom.domain.po.StudyRoomFacility;
import org.yoyo.classroom.domain.vo.SeatWithBookingStatusVO;
import org.yoyo.classroom.domain.vo.StudyRoomDetailVO;
import org.yoyo.classroom.domain.vo.StudyRoomReviewSummary;
import org.yoyo.classroom.mapper.StudyRoomMapper;
import org.yoyo.classroom.domain.po.StudyRoom;
import org.yoyo.classroom.service.StudyRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 自习室业务逻辑层实现类
 */
@Service
public class StudyRoomServiceImpl implements StudyRoomService {

    @Autowired
    private StudyRoomMapper studyRoomMapper;

    /**
     * 根据ID查询自习室
     * @param id 自习室ID
     * @return 自习室对象
     */
    @Override
    public StudyRoom getStudyRoomById(Long id) {
        return studyRoomMapper.selectById(id);
    }

    /**
     * 查询所有自习室
     * @return 自习室列表
     */
    @Override
    public List<StudyRoom> getAllStudyRooms() {
        return studyRoomMapper.selectAll();
    }

    /**
     * 插入自习室
     * @param studyRoom 自习室对象
     * @return 影响的行数
     */
    @Override
    public int addStudyRoom(StudyRoom studyRoom) {
        return studyRoomMapper.insert(studyRoom);
    }

    /**
     * 更新自习室
     * @param studyRoom 自习室对象
     * @return 影响的行数
     */
    @Override
    public int updateStudyRoom(StudyRoom studyRoom) {
        return studyRoomMapper.update(studyRoom);
    }

    /**
     * 删除自习室（逻辑删除）
     * @param id 自习室ID
     * @return 影响的行数
     */
    @Override
    public int deleteStudyRoom(Long id) {
        return studyRoomMapper.delete(id);
    }

    @Override
    public List<StudyRoomReviewSummary> getTopRatedStudyRooms() {
        return studyRoomMapper.getTopRatedStudyRooms();
    }

    @Override
    public StudyRoomDetailVO getStudyRoomDetail(Integer roomId) {
        return studyRoomMapper.getStudyRoomDetail(roomId);
    }

    @Override
    public Page<StudyRoom> getStudyRoomsByFilters(int page, int size, Integer type, String facilities, String sort) {
        Page<StudyRoom> studyRoomPage = new Page<>(page, size);
        List<StudyRoom> studyRooms = studyRoomMapper.getStudyRoomsByFilters(type, facilities, sort);
        studyRoomPage.setRecords(studyRooms);
        return studyRoomPage;
    }

    @Override
    public List<StudyRoomCategory> getAllCategories() {
        return studyRoomMapper.selectAllType();
    }
    @Override
    public List<StudyRoomFacility> getAllStudyRoomFacilities() {
        return studyRoomMapper.selectAllStudyRoomFacilities();
    }

    @Override
    public List<SeatWithBookingStatusVO> getSeatsWithBookingStatus(Long roomId) {
        return studyRoomMapper.getSeatsWithBookingStatus(roomId);
    }

    @Override
    public BookingRule getRoomRuleById(Long roomId) {
        return studyRoomMapper.getRoomRuleById(roomId);
    }
}
